﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MsTestUtilities.RowTests;
using MsTestUtilities.Utilities;

namespace MsTestUtilitiesTests.RowTests.ExpectationTests
{
    [TestClass]
    public class ExactEqualityExpectation
    {
        private Expectation<int> _expectation;

        [TestInitialize]
        public void Setup()
        {
            _expectation = new Expectation<int>(42);
        }

        [TestMethod]
        public void ExpectationIsMet_ReturnTrue()
        {
            ExpectAssertionHolds(_expectation.IsSatisfiedFor(() => 42));
        }

        [TestMethod]
        public void ExpectationIsNotMet_FailureMessageSet()
        {
            var result = _expectation.IsSatisfiedFor(() => 0);
            ExpectAssertionError("Expected <42>. Actual <0>.", result);
        }

        private void ExpectAssertionHolds(AssertionResult actual)
        {
            Assert.IsTrue(actual.AssertionHolds);
        }

        private void ExpectAssertionError(string expectedError, AssertionResult actual)
        {
            Assert.IsFalse(actual.AssertionHolds);
            Assert.AreEqual(expectedError, actual.AssertionError);
        }
    }
}
